﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TaoPortal.Areas.Admin.Models;

namespace TaoPortal.Areas.Admin.Controllers
{
    public class RoleManageController : BaseController
    {
        //
        // GET: /RoleManage/

        public ActionResult Index()
        {
            var v = this.HttpContext.Cache.Get("aaa");
            ViewBag.NavTitle = "角色管理";
            return View();
        }

        [HttpPost]
        public ActionResult AjaxGetList(RoleModel model)
        {
            var data = model.GetRoleList();
            return Content(SerializeJson(new { results = data.Count, rows = data }));
        }

        public ActionResult AddRole()
        {
            RoleModel model = new RoleModel();
            model.Init();
            model.Entity = new AddRole { RoleType = "10" };
            return View(model);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult AddRole(RoleModel model)
        {
            if (ModelState.IsValid)
            {
                model.DoAdd();
                return Content("<script>parent.SubmitSuccess()</script>");
            }
            else
            {
                model.Init();
                return PartialView(model);
            }
        }


        public ActionResult EditRole(string id)
        {
            RoleModel model = new RoleModel();
            model.Init();
            model.InitEntity(id);
            return View(model);
        }

        [HttpPost]
        public ActionResult EditRole(RoleModel model)
        {
            if (ModelState.IsValid)
            {
                model.DoEdit();
                return Content("<script>parent.SubmitSuccess()</script>");
            }
            else
            {
                model.Init();
                return PartialView(model);
            }
        }

        [HttpPost]
        public ActionResult DeleteRole(string id)
        {
            RoleModel model = new RoleModel();
            var res = model.Delete(id);
            return Content(res.ToString());
        }

        public ActionResult Permission()
        {
            ViewBag.NavTitle = "角色权限管理";
            return View();
        }
    }
}
